package com.future.account.controller;

import com.alibaba.fastjson.JSONObject;
import com.future.account.client.EmailClient;
import com.future.account.client.LogClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 账号信息控制器
 *
 * @author shiyong
 * 2022/2/16 9:15
 */
@RestController
@Slf4j
public class AccountInfoController {
    @Resource
    private EmailClient emailClient;

    @Resource
    private LogClient logClient;

    /**
     * 新增账号
     *
     * @param accountName 账号名称
     * @return com.alibaba.fastjson.JSONObject
     * @author shiyong
     * 2022/2/16 9:24
    */
    @PostMapping("/addAccount")
    public JSONObject addAccount(String accountName) {
        // 创建账号
        log.info("创建账号：" + accountName);

        // 将账号信息发送给用户
        String email = "shiyong@163.com";
        String content = "您的账号" + accountName + "已创建成功";
        emailClient.sendEmail(email, content);

        // 记录创建账号的日志
        logClient.addLog("创建账号" + accountName);

        JSONObject result = new JSONObject();
        result.put("msg", "创建账号" + accountName + "成功");
        return result;
    }
}
